package com.member.web.controller.shop;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.member.common.annotation.Log;
import com.member.common.core.controller.BaseController;
import com.member.common.core.domain.AjaxResult;
import com.member.common.core.page.TableDataInfo;
import com.member.common.enums.BusinessType;
import com.member.common.utils.poi.ExcelUtil;
import com.member.shop.domain.SysBizPop;
import com.member.shop.domain.SysBizServiceQuestion;
import com.member.shop.service.ISysBizServiceQuestionService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【客服问题】控制器
 *
 * @author lixinchen
 * @version 1.0
 * @date 2024-10-28
 **/
@RestController
@RequestMapping("/shop/serviceQuestion")
public class SysBizServiceQuestionController extends BaseController {
    @Resource
    private ISysBizServiceQuestionService sysBizServiceQuestionService;

    private void setTenantId(SysBizServiceQuestion sysBizServiceQuestion) {
        Long tenantId = getTenantId();
        if (tenantId != null && tenantId > 0) {
            sysBizServiceQuestion.setTenantId(tenantId);
        }
    }

    /**
     * 查询客服问题列表
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBizServiceQuestion sysBizServiceQuestion) {
        startPage();
        setTenantId(sysBizServiceQuestion);
        List<SysBizServiceQuestion> list = sysBizServiceQuestionService.selectSysBizServiceQuestionList(sysBizServiceQuestion);
        return getDataTable(list);
    }

    /**
     * 导出客服问题列表
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:export')")
    @Log(title = "客服问题", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBizServiceQuestion sysBizServiceQuestion) {
        setTenantId(sysBizServiceQuestion);
        List<SysBizServiceQuestion> list = sysBizServiceQuestionService.selectSysBizServiceQuestionList(sysBizServiceQuestion);
        ExcelUtil<SysBizServiceQuestion> util = new ExcelUtil<SysBizServiceQuestion>(SysBizServiceQuestion.class);
        util.exportExcel(response, list, "客服问题数据");
    }

    /**
     * 获取客服问题详细信息
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysBizServiceQuestionService.selectSysBizServiceQuestionById(id));
    }

    /**
     * 新增客服问题
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:add')")
    @Log(title = "客服问题", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysBizServiceQuestion sysBizServiceQuestion) {
        return toAjax(sysBizServiceQuestionService.insertSysBizServiceQuestion(sysBizServiceQuestion));
    }

    /**
     * 修改客服问题
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:edit')")
    @Log(title = "客服问题", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysBizServiceQuestion sysBizServiceQuestion) {
        return toAjax(sysBizServiceQuestionService.updateSysBizServiceQuestion(sysBizServiceQuestion));
    }

    /**
     * 删除客服问题
     */
    @PreAuthorize("@ss.hasPermi('shop:serviceQuestion:remove')")
    @Log(title = "客服问题", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysBizServiceQuestionService.deleteSysBizServiceQuestionByIds(ids));
    }
}
